from appium.webdriver.common.mobileby import MobileBy

from page.addmember_page import AddMemberPage
from page.basepage import BasePage
from page.memberinfo_page import MemberInfoPage


class ContactListPage(BasePage):

    step_path = 'contactlist_page.yaml'
    def goto_addmember(self):
        self.steps(self.step_path, "goto_addmember")
        return AddMemberPage(self.driver)

    #需要将参数传进来，因为要根据传入的名称，在页面点击对应的成员
    def goto_member_info(self, dict):
        target_text = dict['name']
        ui_text = f'new UiScrollable(new UiSelector().scrollable(true).instance(0)).' \
                  f'scrollIntoView(new UiSelector().text("{target_text}").instance(0))'
        ele = self.driver.find_element(MobileBy.ANDROID_UIAUTOMATOR, ui_text)
        ele.click()
        return MemberInfoPage(self.driver)

    def verify_member_del(self,dict):
        #通过查询查找是否有搜索结果，如果返回无搜索结果，则表示用户删除成功
        self._params = dict
        self.steps(self.step_path, "verify_member_del")
        result = self.find(MobileBy.XPATH, "//*[@text='无搜索结果']").text
        return result
